//
// Created by Tan Ke on 2023/12/4.
//

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>

bool isPalindrome(char* s)
{
    char *str1 = (char *)malloc(sizeof(char) * (strlen(s) + 1));
    memset(str1, 0, (strlen(s) + 1));
    int m = 0;

    for (int i = 0; i < strlen(s); i ++) {
        if (s[i] >= 'a' && s[i] <= 'z') {
            str1[m] = s[i];
            m++;
        } else if (s[i] >= 'A' && s[i] <= 'Z') {
            str1[m] = s[i] - 'A' + 'a';
            m++;
        } else if (s[i] >= '0' && s[i] <= '9') {
            str1[m] = s[i];
            m++;
        } else {
            continue;
        }
    }

    if (m == 0) {
        return true;
    }

    for (int i = 0; i < m / 2; i ++) {
        if (str1[i] != str1[m - i - 1]) {
            return false;
        }
    }

    return true;
}

int main(void)
{
    const char* s = "A man, a plan, a canal: Panama";
    printf("%d\n", isPalindrome(s));

    const char* s1 = "race a car";
    printf("%d\n", isPalindrome(s1));

    const char* s2 = " ";
    printf("%d\n", isPalindrome(s2));
    return 0;
}
